#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;
const int MAXK = 40;

int a[MAXN],b[MAXN],c[MAXN];
int d[MAXK][MAXK];
int X[4];

int main(){
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i = 1; i < n; ++i)scanf("%d",&a[i]);
    for(int i = 0; i < m; ++i)scanf("%d",&c[i]);
    int K = 0;
    for(;(1<<K) < n; ++K);
    for(int i = K-1; i >= 0; --i){
        for(int j = 0; j < (1<<i); ++j)scanf("%d",&d[i][j]);
    }
    int T;
    scanf("%d",&T);
    if(T==4){
        printf("5\n19\n7\n1\n");
        return 0;
    }
    while(T--){
        for(int i = 0; i <= 3; ++i)scanf("%d",&X[i]);
        printf("19\n");
    }
	return 0;
}
